package com.heima.kafka.listener;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojo.User;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.TopicPartition;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class HelloListener {

    @KafkaListener(topics = "user-topic", topicPartitions = {
            @TopicPartition(topic = "user-topic", partitions = {"1"})
    })
    public void onMessage(String message) {
        if (!StringUtils.isEmpty(message)) {
            User user = JSON.parseObject(message, User.class);
            String username = user.getUsername();
            Integer age = user.getAge();
            System.out.println(user);
            System.out.println(username + age);
        }

    }
}